package com.ruoyi.web.controller.adopt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.adopt.domain.RecentSituation;
import com.ruoyi.adopt.service.IRecentSituationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 近况Controller
 *
 * @author shilling
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/adopt/situation")
public class RecentSituationController extends BaseController
{
    @Autowired
    private IRecentSituationService recentSituationService;

    /**
     * 查询近况列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RecentSituation recentSituation)
    {
        startPage();
        List<RecentSituation> list = recentSituationService.selectRecentSituationList(recentSituation);
        return getDataTable(list);
    }

    /**
     * 导出近况列表
     */
    @Log(title = "近况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecentSituation recentSituation)
    {
        List<RecentSituation> list = recentSituationService.selectRecentSituationList(recentSituation);
        ExcelUtil<RecentSituation> util = new ExcelUtil<RecentSituation>(RecentSituation.class);
        util.exportExcel(response, list, "近况数据");
    }

    /**
     * 获取近况详细信息
     */
    @GetMapping(value = "/{recentSituationId}")
    public AjaxResult getInfo(@PathVariable("recentSituationId") Long recentSituationId)
    {
        return AjaxResult.success(recentSituationService.selectRecentSituationByRecentSituationId(recentSituationId));
    }

    /**
     * 新增近况
     */
    @Log(title = "近况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecentSituation recentSituation)
    {
        return toAjax(recentSituationService.insertRecentSituation(recentSituation));
    }

    /**
     * 修改近况
     */
    @Log(title = "近况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecentSituation recentSituation)
    {
        return toAjax(recentSituationService.updateRecentSituation(recentSituation));
    }

    /**
     * 删除近况
     */
    @Log(title = "近况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recentSituationIds}")
    public AjaxResult remove(@PathVariable Long[] recentSituationIds)
    {
        return toAjax(recentSituationService.deleteRecentSituationByRecentSituationIds(recentSituationIds));
    }
}
